<template>
	<section>
		<el-row class="app-container">
			<!--新增界面 ImGroup 群组定义--> 
			<el-form :model="addForm"  label-width="120px" :rules="addFormRules" ref="addForm">
				<el-form-item label="群组主键" prop="id">
					<el-input v-model="addForm.id" placeholder="群组主键" ></el-input>
				</el-form-item> 
				<el-form-item label="组名" prop="groupName">
					<el-input v-model="addForm.groupName" placeholder="组名" ></el-input>
				</el-form-item> 
				<el-form-item label="组类别" prop="categoryId">
					<el-input v-model="addForm.categoryId" placeholder="组类别" ></el-input>
				</el-form-item> 
				<el-form-item label="创建人编号" prop="cuserid">
					<el-input v-model="addForm.cuserid" placeholder="创建人编号" ></el-input>
				</el-form-item> 
				<el-form-item label="创建人姓名" prop="cusername">
					<el-input v-model="addForm.cusername" placeholder="创建人姓名" ></el-input>
				</el-form-item> 
				<el-form-item label="创建日期" prop="cdate">
					<el-date-picker type="date" placeholder="选择日期" v-model="addForm.cdate" value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd"></el-date-picker>
				</el-form-item> 
				<el-form-item label="业务状态0已提出1咨询中2已结束" prop="bizStatus">
					<el-input v-model="addForm.bizStatus" placeholder="业务状态0已提出1咨询中2已结束" ></el-input>
				</el-form-item> 
				<el-form-item label="群状态0初始1有效2已解散3全体禁言" prop="gstatus">
					<el-input v-model="addForm.gstatus" placeholder="群状态0初始1有效2已解散3全体禁言" ></el-input>
				</el-form-item> 
				<el-form-item label="响应状态：I正在响应，S退出响应，O超时未响应，F结束响应" prop="resStatus">
					<el-input v-model="addForm.resStatus" placeholder="响应状态：I正在响应，S退出响应，O超时未响应，F结束响应" ></el-input>
				</el-form-item> 
				<el-form-item label="门店编号" prop="locationId">
					<el-input v-model="addForm.locationId" placeholder="门店编号" ></el-input>
				</el-form-item> 
				<el-form-item label="商户编号" prop="shopId">
					<el-input v-model="addForm.shopId" placeholder="商户编号" ></el-input>
				</el-form-item> 
				<el-form-item label="归属机构号" prop="branchId">
					<el-input v-model="addForm.branchId" placeholder="归属机构号" ></el-input>
				</el-form-item> 
				<el-form-item label="在线人数" prop="onlineUsers">
					<el-input v-model="addForm.onlineUsers" placeholder="在线人数" ></el-input>
				</el-form-item> 
				<el-form-item label="归属部门" prop="deptid">
					<el-input v-model="addForm.deptid" placeholder="归属部门" ></el-input>
				</el-form-item> 
				<el-form-item label="是否允许加入0不允许1允许" prop="allowJoin">
					<el-input v-model="addForm.allowJoin" placeholder="是否允许加入0不允许1允许" ></el-input>
				</el-form-item> 
				<el-form-item label="是否需要审核0不需要1需要" prop="needAudit">
					<el-input v-model="addForm.needAudit" placeholder="是否需要审核0不需要1需要" ></el-input>
				</el-form-item> 
				<el-form-item label="群头像地址" prop="headimgurl">
					<el-input v-model="addForm.headimgurl" placeholder="群头像地址" ></el-input>
				</el-form-item> 
				<el-form-item label="下次允许发言时间" prop="allowSpeechTime">
					<el-date-picker type="date" placeholder="选择日期" v-model="addForm.allowSpeechTime" value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd"></el-date-picker>
				</el-form-item> 
				<el-form-item label="是否为私聊群0否1是两人人对话有第三人加入自动升级为普通群" prop="isPrichat">
					<el-input v-model="addForm.isPrichat" placeholder="是否为私聊群0否1是两人人对话有第三人加入自动升级为普通群" ></el-input>
				</el-form-item> 
				<el-form-item>
					<el-col :span="24" :offset="8"> 
						<el-button @click.native="handleCancel">取消</el-button>  
						<el-button v-loading="load.add" type="primary" @click.native="addSubmit" :disabled="load.add==true">提交</el-button>  
					</el-col>
				</el-form-item> 
			</el-form>
		</el-row>
	</section>
</template>

<script>
	import util from '@/common/js/util';//全局公共库
	//import { listOption } from '@/api/mdp/meta/itemOption';//下拉框数据查询 
	import { addImGroup } from '@/api/mdp/im/group/imGroup';
	import { mapGetters } from 'vuex'
	
	export default { 
		computed: {
		    ...mapGetters([
		      'userInfo'
		    ])
		},
		props:['imGroup','visible'],
		watch: {
	      'imGroup':function( imGroup ) {
	        this.addForm = imGroup;
	      },
	      'visible':function(visible) { 
	      	if(visible==true){
	      		//从新打开页面时某些数据需要重新加载，可以在这里添加
	      	}
	      } 
	    },
		data() {
			return {
				options:{},//下拉选择框的所有静态数据  params=[{categoryId:'0001',itemCode:'sex'}] 返回结果 {'sex':[{optionValue:'1',optionName:'男',seqOrder:'1',fp:'',isDefault:'0'},{optionValue:'2',optionName:'女',seqOrder:'2',fp:'',isDefault:'0'}]} 
				load:{ list: false, edit: false, del: false, add: false },//查询中...
				addFormRules: {
					id: [
						//{ required: true, message: '群组主键不能为空', trigger: 'blur' }
					]
				},
				//新增界面数据 群组定义
				addForm: {
					id:'',groupName:'',categoryId:'',cuserid:'',cusername:'',cdate:'',bizStatus:'',gstatus:'',resStatus:'',locationId:'',shopId:'',branchId:'',onlineUsers:'',deptid:'',allowJoin:'',needAudit:'',headimgurl:'',allowSpeechTime:'',isPrichat:''
				}
				/**begin 在下面加自定义属性,记得补上面的一个逗号**/
				
				/**end 在上面加自定义属性**/
			}//end return
		},//end data
		methods: {
			// 取消按钮点击 父组件监听@cancel="addFormVisible=false" 监听
			handleCancel:function(){
				this.$refs['addForm'].resetFields();
				this.$emit('cancel');
			},
			//新增提交ImGroup 群组定义 父组件监听@submit="afterAddSubmit"
			addSubmit: function () {
				
				this.$refs.addForm.validate((valid) => {
					if (valid) {
						
						this.$confirm('确认提交吗？', '提示', {}).then(() => { 
							this.load.add=true
							let params = Object.assign({}, this.addForm); 
							addImGroup(params).then((res) => {
								this.load.add=false
								var tips=res.data.tips;
								if(tips.isOk){
									this.$refs['addForm'].resetFields();
									this.$emit('submit');//  @submit="afterAddSubmit"
								}
								this.$message({ message: tips.msg, type: tips.isOk?'success':'error' }); 
							}).catch( err  => this.load.add=false);
						});
					}
				});
			}
			/**begin 在下面加自定义方法,记得补上面的一个逗号**/
				
			/**end 在上面加自定义方法**/
			
		},//end method
		components: {  
		    //在下面添加其它组件 'im-group-edit':ImGroupEdit
		},
		mounted() {
			this.addForm=Object.assign(this.addForm, this.imGroup);  
			/**在下面写其它函数***/
			
		}//end mounted
	}

</script>

<style scoped>

</style>